
//---------common begin----------------------
var eventbegin = function(param){
};
var eventerror = function(data){
};
var eventend = function(data){
};
var error = "";
function getCommonAjax(param, params, enablePost){
    param = param;
    eventbegin(param);
    httptype = "GET";
    if (arguments.length > 2) {
        httptype = "POST";
    }
	
    
    var options = {
        "admincommon_param": param
    };
    params = params ||
    {};
    $.extend(options, params);
    $.ajax({
        type: httptype,
        url: "ajaxpage.aspx",
        data: options,
        cache: false,
        success: function(data){
            var dataType = typeof data;
            
            if (dataType == "string") {
                $("#ajaxload").html("loading...").show();
                eventend(data, param);
            }
            else {
                alert($(data).find("CallbackError").text());
            }
        },
        complete: function(){
            $("#ajaxload").hide();
        },
        error: function(request, settings){
            alert(settings.url);
            //alert("服务器出错,请重试");
        }
    });
}


function BaseSvcAjax(ajaxparam, params, svctype){

    eventbegin(params);
    var httptype = "POST";
    if (svctype) {
        httptype = svctype;
    }
    var options = {};
    $.extend(options, params);
    $.ajax({
        dataType: ajaxparam.dataType || "text",
        type: httptype,
        url: ajaxparam.url,
        data: options,
        cache: false,
        success: function(data){
        
            var dataType = typeof data;
            
            if (dataType == "string" || ajaxparam.dataType == "json") {
                $("#ajaxload").html("loading...").show();
                eventend(data, params);
                
            }
            
            else {
                alert($(data).find("CallbackError").text());
            }
        },
        complete: function(){
            $("#ajaxload").hide();
        },
        error: function(request, settings){
            alert(request.responseText);
            //alert("服务器出错,请重试");
        
        }
    });
}


function SvcAjax(ajaxparams, params, eventhandle, httptype){
    if (eventhandle) 
        eventhandle;
    BaseSvcAjax(ajaxparams, params, httptype);
}



function getCommonContent(param, params, eventhandle, httptype){
    if (arguments.length < 4) 
        httptype = false;
    
    if (eventhandle) 
        eventhandle;
    if (httptype) {
        getCommonAjax(param, params, true);
    }
    else {
        getCommonAjax(param, params);
    }
}

function showLoading(){
    $("#innerContent").innerHTML = "loading..."
}

function defautEvent(){
    eventbegin = function(){
        $("#ajaxload").html("loading...").show();
    }
    eventend = function(data, param){
        $("#innerContent").html(data);
        switch (param) {
            case "linkContent":
                $("#linkBtn").click(function(){
                    AdminCommon.saveLink();
                    return false;
                })
                break;
            case "announce":
                //submit
                $("#submit").click(function(){
                    AdminCommon.saveAnnounce();
                    return false;
                })
                break;
            case "group":
                $("#submit").click(function(){
                    AdminUserGroup.SelectAction();
                    return false;
                })
                break;
            case "categoryContent":
                $("#submit").click(function(){
                    AdminCategory.selectAction();
                    return false;
                })
                break;
            case "wordFilter":
                $("#submit").click(function(){
                    AdminWordFilter.selectAction();
                    return false;
                })
                break;
            case "smile":
                
                $("#submit").click(function(){
                    AdminSmile.selectAction();
                    return false;
                })
                
                break;
            case "extensionLink":
                
                $("#submit").click(function(){
                    AdminExtensionLink.selectAction();
                    return false;
                })
                break;
            case "widget":
                
                $("#submit").click(function(){
                    AdminWidget.selectAction();
                    return false;
                })
                break;
            case "settings":
                addEvents();
                checkAllRadio();
                addID();
                break;
        }
    }
}

function checkRadio(name, value){
    var form = document.getElementsByName("form1");
    for (var i = 0; i < form.elements.length; i++) {
        var ele = form.elements[i];
        if (ele.name == name && ele.value == value) {
        
            ele.checked = "checked";
        }
    }
}


function saveEvent(module){

    eventend = function(){
        DoCallback(module);
    }
}

function getCommonModule(param){
    getCommonContent(params, {}, defautEvent());
}

function DoCallback(param, httptype){
    getCommonContent(param, {}, defautEvent());
}

function MiscCallback(param, httptype){
    getCommonContent(param, {}, miscEvent());
}

function miscEvent(){
    eventbegin = function(){
        $("#message").html("正在处理....");
    }
    eventend = function(){
        $("#message").html("处理完成");
    }
}

var AdminUserGroup = {

    Callback: function(params, httptype){
    
        if (arguments.length == 1) {
            httptype = 'get'
        }
        ShowLoading();
        new Ajax.Request("ajax.aspx", {
            method: httptype,
            parameters: {
                admincommon_param: params
            },
            onSuccess: function(json){
                $("#innerContent").innerHTML = json.responseText;
            }
        })
    },
    SelectAction: function(){
    
        switch ($("#act").val()) {
            case "update":
                
                getCommonContent(this.SaveGroup(), {}, saveEvent("group"), true)
                
                break;
            case "delete":
                getCommonContent(this.DeleteGroup(), {}, saveEvent("group"), true)
                
                break;
        }
    },
    SaveGroup: function(){
        var selectArray = new Array();
        var nameArray = new Array();
        var viewArray = new Array();
        var postArray = new Array();
        var editArray = new Array();
        var deleteArray = new Array();
        var uploadArray = new Array();
        var rights = new Array();
        var groupArray = new Array();
        groupArray[0] = "updateUserGroup";
        var groupSelectList = document.getElementsByName("groupSelect");
        var groupNameList = document.getElementsByName("name");
        var groupViewList = document.getElementsByName("view");
        var groupPostList = document.getElementsByName("post");
        var groupEditList = document.getElementsByName("edit");
        var groupDeleteList = document.getElementsByName("delete");
        var groupUploadList = document.getElementsByName("upload");
        for (var i = 1; i < groupSelectList.length; i++) {
        
            selectArray.push(groupSelectList[i].value);
            rights.push(groupViewList[i].value +
            groupPostList[i].value +
            groupEditList[i].value +
            groupDeleteList[i].value +
            groupUploadList[i].value)
            nameArray.push(groupNameList[i].value);
            
        }
        groupArray.push(selectArray);
        groupArray.push(nameArray);
        groupArray.push(rights);
        if ($("#newName").val().length > 0) 
            groupArray.push(this.AddGroup());
        return groupArray;
    },
    AddGroup: function(){
        var group = new Array();
        group.push($("#newName").val());
        group.push($("#newView").val() + $("#newPost").val() + $("#newEdit").val() + $("#newDelete").val() + $("#newUpload").val());
        return group;
    },
    DeleteGroup: function(){
        var checkArray = new Array();
        checkArray[0] = "deleteUserGroup";
        var groupSelectList = document.getElementsByName("groupSelect");
        for (var i = 0; i < groupSelectList.length; i++) {
            if (groupSelectList[i].checked) {
                checkArray.push(groupSelectList[i].value);
            }
        }
        return checkArray;
    }
}
var textContent = function(){
}
textContent.Callback = function(paramArray){
    DoCallback(paramArray)
}

var AdminSmile = {
    selectAction: function(){
        switch ($("#act").val()) {
            case "update":
                getCommonContent(this.saveAll(), {}, saveEvent("smile"), true);
                break;
            case "delete":
                var deleteArray = checkAll("deleteSmile");
                if (deleteArray.length > 1) {
                    getCommonContent(deleteArray, {}, saveEvent("smile"), true);
                }
                else {
                    alert("未选中任何项");
                }
                break;
        }
    },
    saveAll: function(){
        var checkArray = new Array();
        var imageArray = new Array();
        var codeArray = new Array();
        var smile = new Array();
        smile[0] = "savesmile";
        var form = document.getElementById("form1");
        for (var i = 0; i < form.elements.length; i++) {
            if (form.elements[i].type == "checkbox") {
                checkArray.push(form.elements[i].value);
            }
            if (form.elements[i].name == "code") {
                codeArray.push(form.elements[i].value);
            }
            if (form.elements[i].name == "image") {
                imageArray.push(form.elements[i].value);
            }
        }
        smile.push(checkArray);
        smile.push(imageArray);
        smile.push(codeArray);
        if ($("#smilecode").val().length > 0) 
            smile.push(this.addSmile());
        return smile;
    },
    addSmile: function(){
        var paramArray = new Array();
        paramArray[0] = $("#smilecode").val();
        paramArray[1] = $("#smileimage").val();
        
        return paramArray
    },
    deleteSmile: function(){
        return checkAll("deletesmile");
    }
}

var AdminCategory = {
    selectAction: function(){
        switch ($("#act").val()) {
            case "update":
                getCommonContent(this.saveCatAll(), {}, saveEvent("categoryContent"), true);
                break;
            case "delete":
                var deleteArray = checkAll("deleteCategory");
                if (deleteArray.length > 1) {
                    getCommonContent(checkAll("deleteCategory"), {}, saveEvent("categoryContent"), true);
                }
                else {
                    alert("未选中任何项");
                }
                break;
            case "move":
                
                this.moveReady();
                break;
        }
    },
    saveCatAll: function(){
        var checkArray = new Array();
        var nameArray = new Array();
        var hiddenArray = new Array();
        var lockArray = new Array();
        var orderArray = new Array();
        
        var catArray = new Array();
        
        catArray[0] = "saveCategory";
        var form = document.getElementById("form1");
        
        for (var i = 0; i < form.elements.length; i++) {
            if (form.elements[i].name == "selected") {
                checkArray.push(form.elements[i].value);
            }
            if (form.elements[i].name == "name") {
                nameArray.push(form.elements[i].value);
            }
            if (form.elements[i].name == "hidden") {
                hiddenArray.push(form.elements[i].checked);
            }
            if (form.elements[i].name == "locked") {
                lockArray.push(form.elements[i].checked);
            }
            if (form.elements[i].name == "order") {
                orderArray.push(form.elements[i].value);
            }
        }
        
        catArray.push(checkArray);
        catArray.push(nameArray);
        catArray.push(hiddenArray);
        catArray.push(lockArray);
        catArray.push(orderArray);
        
        if ($("#newname").val().length > 0) 
            catArray.push(this.addCategory());
        return catArray;
    },
    addCategory: function(){
        var catArray = new Array();
        catArray[0] = $("#newname").val();
        catArray[1] = $("#newHidden").attr("checked") ? true : false;
        catArray[2] = $("#newLocked").attr("checked") ? true : false;
        catArray[3] = $("#neworder").val();
        return catArray;
    },
    saveCategory: function(){
        var catArray = this.saveCatAll();
        getCommonContent(catArray, {}, saveEvent("categoryContent"), true);
    },
    moveReady: function(){
        $("#movepanel").show();
        $("#catpanel").hide();
        var moveArray = checkAll("moveCategory", true);
        if (moveArray.length > 1) {
            $("#movesubmit").click(function(){
                moveArray.push($("#ctl02_targetCat").val());
                AdminCategory.moveCategory(moveArray);
                return false;
            })
            $("#back").click(function(){
                $("#movepanel").hide();
                $("#catpanel").show();
                $("input").attr("checked", "");
                return false;
            })
            return moveArray;
        }
        else {
            alert("未选中任何项");
        }
    },
    moveCategory: function(moveArray){
        getCommonContent(moveArray, {}, saveEvent("categoryContent"), true);
    }
}
var AdminExtensionLink = {
    selectAction: function(){
        switch ($("#act").val()) {
            case "update":
                
                getCommonContent(this.saveLinkAll(), {}, saveEvent("extensionLink"), true);
                break;
            case "delete":
                var deleteArray = checkAll("deleteExtensionLink");
                if (deleteArray.length > 1) {
                    getCommonContent(deleteArray, {}, saveEvent("extensionLink"), true);
                }
                else {
                    alert("未选中任何项");
                }
                break;
        }
    },
    saveLinkAll: function(){
        var checkArray = new Array();
        var nameArray = new Array();
        var urlArray = new Array();
        var extensionsArray = new Array();
        var orderArray = new Array();
        var wordArray = new Array();
        wordArray[0] = "saveExtensionLink";
        var form = document.getElementById("form1");
        
        for (var i = 0; i < form.elements.length; i++) {
            if (form.elements[i].name == "selected") {
            
                checkArray.push(form.elements[i].value);
            }
            if (form.elements[i].name == "name") {
                nameArray.push(form.elements[i].value);
            }
            if (form.elements[i].name == "url") {
                urlArray.push(form.elements[i].value);
            }
            if (form.elements[i].name == "extensions") {
                extensionsArray.push(form.elements[i].value);
            }
            if (form.elements[i].name == "order") {
                orderArray.push(form.elements[i].value);
            }
        }
        
        wordArray.push(checkArray);
        wordArray.push(nameArray);
        wordArray.push(urlArray);
        wordArray.push(extensionsArray);
        wordArray.push(orderArray);
        if ($("#newname").val().length > 0) 
            wordArray.push(this.addLink());
        return wordArray;
    },
    addLink: function(){
        var wordArray = new Array();
        wordArray[0] = $("#newname").val();
        wordArray[1] = $("#newurl").val();
        wordArray[2] = $("#newextensions").val();
        wordArray[3] = $("#neworder").val();
        return wordArray;
    }
}

var AdminWidget = {
    selectAction: function(){
        switch ($("#act").val()) {
            case "update":
                getCommonContent(this.saveWidgetAll(), {}, saveEvent("widget"), true);
                break;
            case "delete":
                var deleteArray = checkAll("deleteWidget");
                if (deleteArray.length > 1) {
                    getCommonContent(deleteArray, {}, saveEvent("widget"), true);
                }
                else {
                    alert("未选中任何项");
                }
                break;
        }
    },
    saveWidgetAll: function(){
        var checkArray = new Array();
        var hiddenArray = new Array();
        var typeArray = new Array();
        var titleArray = new Array();
        var nameArray = new Array();
        var orderArray = new Array();
        var wordArray = new Array();
        wordArray[0] = "saveWidget";
        var form = document.getElementById("form1");
        
        for (var i = 0; i < form.elements.length; i++) {
            var element = form.elements[i];
            switch (element.name) {
                case "selected":
                    checkArray.push(element.value);
                    break;
                case "hidden":
                    hiddenArray.push(element.checked ? true : false);
                    break;
                case "type":
                    typeArray.push(element.value);
                    break;
                case "title":
                    titleArray.push(element.value);
                    break;
                case "name":
                    nameArray.push(element.value);
                    break;
                case "order":
                    orderArray.push(element.value);
                    break;
            }
            
        }
        
        wordArray.push(checkArray);
        wordArray.push(hiddenArray);
        wordArray.push(typeArray);
        wordArray.push(titleArray);
        wordArray.push(nameArray);
        wordArray.push(orderArray);
        if ($("#newtitle").val().length > 0) 
            wordArray.push(this.addWidget());
        return wordArray;
    },
    addWidget: function(){
        var wordArray = new Array();
        wordArray[0] = $("#newhidden").attr("checked") ? true : false;
        wordArray[1] = $("#newtype").val();
        wordArray[2] = $("#newtitle").val();
        wordArray[3] = $("#newname").val();
        wordArray[4] = $("#neworder").val();
        
        return wordArray;
    }
}



var AdminWordFilter = {
    selectAction: function(){
        switch ($("#act").val()) {
            case "update":
                
                getCommonContent(this.saveWordAll(), {}, saveEvent("wordFilter"), true);
                break;
            case "delete":
                var deleteArray = checkAll("deleteWordFilter");
                if (deleteArray.length > 1) {
                    getCommonContent(deleteArray, {}, saveEvent("wordFilter"), true);
                }
                else {
                    alert("未选中任何项");
                }
                break;
        }
    },
    addWordFilter: function(){
        var wordArray = new Array();
        wordArray[0] = $("#newtext").val();
        wordArray[1] = $("#newreplace").val();
        wordArray[2] = $("#newRegexp").attr("checked") ? true : false;
        wordArray[3] = $("#newmode").val();
        return wordArray;
    },
    saveWordAll: function(){
        var checkArray = new Array();
        var textArray = new Array();
        var replaceArray = new Array();
        var regexpArray = new Array();
        var modeArray = new Array();
        var wordArray = new Array();
        wordArray[0] = "saveWordFilter";
        var form = document.getElementById("form1");
        
        for (var i = 0; i < form.elements.length; i++) {
            if (form.elements[i].name == "selected") {
                checkArray.push(form.elements[i].value);
            }
            if (form.elements[i].name == "text") {
                textArray.push(form.elements[i].value);
            }
            if (form.elements[i].name == "replace") {
                replaceArray.push(form.elements[i].value);
            }
            if (form.elements[i].name == "regexp") {
                regexpArray.push(form.elements[i].checked);
            }
            if (form.elements[i].name == "mode") {
                modeArray.push(form.elements[i].selectedIndex);
            }
        }
        
        wordArray.push(checkArray);
        wordArray.push(textArray);
        wordArray.push(replaceArray);
        wordArray.push(regexpArray);
        wordArray.push(modeArray);
        if ($("#newtext").val().length > 0) 
            wordArray.push(this.addWordFilter());
        return wordArray;
    }
    
}

function checkAll(action, showName){
    var checkArray = new Array();
    checkArray[0] = action;
    var selectedList = document.getElementsByName("selected");
    var nameList = document.getElementsByName("name");
    $("#souce").html("");
    for (var i = 0; i < selectedList.length; i++) {
        if (selectedList[i].checked) {
            if (arguments.length > 1) {
                $("#souce").append("[" + nameList[i].value + "]");
            }
            
            checkArray.push(selectedList[i].value);
        }
    }
    
    return checkArray;
}


var AdminCommon = {
    saveLink: function(){
        var linkArray = new Array();
        linkArray.push("updateLink");
        
        linkArray.push($("#menulLinks").val());
        linkArray.push($("#friendlinks").val());
        getCommonContent(linkArray, {}, this.saveEvent("linkContent"), true);
    },
    saveEvent: function(module){
        eventend = function(){
            DoCallback(module);
        }
    },
    saveAnnounce: function(){
        var announceArray = new Array();
        announceArray[0] = "updateAnnounce";
        
        var showChecked = $("#show").attr("checked") ? true : false;
        showChecked ? announceArray[1] = 1 : announceArray[1] = 0;
        announceArray[2] = $("#message").val();
        getCommonContent(announceArray, {}, this.saveEvent("announce"), true);
        
    },
    miscCallback: function(params){
        $("message").innerHTML = "正在处理中...";
        new Ajax.Request("default.aspx", {
            method: 'post',
            parameters: {
                misc_param: params
            },
            onSuccess: function(json){
                $("message").innerHTML = "成功"
            }
        })
    },
    
    saveSettings: function(action){
    
        var setArray = new Array();
        setArray[0] = action;
        setArray[1] = $("#blogTitle").val();
        setArray[2] = $("#blogDescription").val();
        setArray[3] = $("#baseURL").val();
        setArray[4] = $("#logoImage").val();
        setArray[5] = $("#blogWebMaster").val();
        setArray[6] = $("#blogWebMasterEmail").val();
        setArray[7] = $("#blogLanguage").val();
        setArray[8] = getCheck("defaultViewMode");//defaultViewMode
        setArray[9] = $("#articlePerPageNormal").val();
        setArray[10] = $("#articlePerPageList").val();
        setArray[11] = $("#listEntryPerPage").val();
        setArray[12] = $("#commentPerPage").val();
        setArray[13] = getCheck("commentTimeOrder");//
        setArray[14] = $("#showTrackbackWithComment").val();
        setArray[15] = getCheck("showTrackbackPosition");//
        setArray[16] = $("#recentArticleList").val();
        setArray[17] = $("#recentCommentList").val();
        setArray[18] = $("#enableDynamicCalendar").val();
        //
        setArray[19] = $("#enableContentAutoSplit").val();
        
        setArray[20] = $("#contentAutoSplitChars").val();
        setArray[21] = $("#enableRegister").val();
        setArray[22] = $("#enableSecurityCode").val();
        setArray[23] = $("#enableTrackbackIn").val();
        setArray[24] = $("#enableTrackbackOut").val();
        //
        setArray[25] = $("#enableComment").val();
        setArray[26] = $("#maxCommentLength").val();
        setArray[27] = $("#maxCommentURLCount").val();
        setArray[28] = $("#enableGuestBook").val();
        setArray[29] = $("#entryPerPageGuestBook").val();
        //
        setArray[30] = $("#styleSheet").val();
        setArray[31] = $("#imageFolder").val();
        setArray[32] = $("#smiliesFolder").val();
        //
        setArray[33] = $("#smiliesPerRow").val();
        setArray[34] = $("#minPostDuration").val();
        setArray[35] = $("#enableVisitorRecord").val();
        setArray[36] = $("#maxVisitorRecord").val();
        setArray[37] = $("#enableUpload").val();
        setArray[38] = $("#uploadSize").val();
        setArray[39] = $("#uploadPath").val();
        setArray[40] = $("#uploadTypes").val();
        setArray[41] = $("#foot").val();
        getCommonContent(setArray, {}, this.saveEvent("settings"), true);
    }
}

var AdminFile = {
    DeleteFile: function(path){
        getCommonContent("attachments", {
            "action": "delete",
            "file": escape(path)
        }, defautEvent());
    },
    DeleteFolder: function(path){
        getCommonContent("attachments", {
            "action": "delete",
            "folder": escape(path)
        }, defautEvent());
    },
    GetFile: function(path){
    
        getCommonContent("attachments", {
            "path": encodeURI(path)
        }, defautEvent());
    }
}

var AdminDataBase = {
    backup: function(){
        getCommonContent("database", {
            "action": "backup"
        }, defautEvent());
    },
    compact: function(){
        getCommonContent("database", {
            "action": "compact"
        }, defautEvent());
    },
    restore: function(path){
        getCommonContent("database", {
            "action": "restore",
            "file": encodeURI(path)
        }, defautEvent());
    },
    deleteData: function(path){
        getCommonContent("database", {
            "action": "delete",
            "file": encodeURI(path)
        }, defautEvent());
    }
}

var AdminPlugin = {
    Install: function(pluginName){
        var workArray = new Array();
        workArray.push("Install");
        workArray.push(pluginName);
        getCommonContent(workArray, {}, saveEvent("plugins"), true);
    },
    UnInstall: function(pluginName){
        var workArray = new Array();
        workArray.push("UnInstall");
        workArray.push(pluginName);
        getCommonContent(workArray, {}, saveEvent("plugins"), true);
    },
    PluginEvent: function(){
        eventend = function(){
            alert("xxx");
        }
    }
}

var AdminComment = {
    getComment: function(){
    
    }
}

var NLBSTheme = {
    ChangeTheme: function(name){
        getCommonContent("changeTheme", {
            themeName: name
        }, this.ThemeCallEvent(name), true);
    },
    ThemeCallEvent: function(name){
        eventbegin = function(){
            $("#ajaxload").html("loading...").show();
        }
        eventend = function(data, param){
            $("#skin").attr("href", "/styles/" + name + "/styles.css");
            //alert("设置成功");
        }
    }
}

function CommentCallEvent(){
    eventbegin = function(){
        $("#ajaxload").html("loading...").show();
    }
    eventend = function(data, param){
        $("#adminComment").html(data);
        var checkbox = document.createElement("input");
        checkbox.type = "checkbox";
        CommentCheck($("#adminComment").find(".commentbox-title"))
        
        $("#adminComment").find("#innerContent").css("margin-left", "0px");
    }
}

//
function GuestBookCallEvent(){
    eventbegin = function(){
        $("#ajaxload").html("loading...").show();
    }
    eventend = function(data, param){
        $("#adminGuestbook").html(data);
        $("#commentForm").remove();
        CommentCheck($("#adminGuestbook").find(".gbbox-title"));
        $("#adminGuestbook").find("#innerContent").css("margin-left", "0px");
    }
}

function TrackBackCallEvent(){
    eventbegin = function(){
        $("#ajaxload").html("loading...").show();
    }
    eventend = function(data, param){
        $("#adminTrackback").html(data);
        CommentCheck($("#adminTrackback").find(".trackbackbox-title"));
        
        $("#adminTrackback").find("#innerContent").css("margin-left", "0px");
    }
}

function CommentCheck(obj){
    obj.each(function(){
        var checkbox = document.createElement("input");
        checkbox.type = "checkbox";
        $(checkbox).prependTo($(this));
        $(checkbox).click(function(){
            if ($(this).attr("checked")) {
                $(this).parent().css("background-color", "red");
            }
            else {
                $(this).parent().css("background-color", "");
            }
        })
    });
    $(".checkall,.delete").unbind();
    $(".checkall").click(function(){
        currentCommentPanel.find("input:checkbox").each(function(i){
            if (this.checked == true) {
                this.checked = false;
                $(this).parent().css("background-color", "");
            }
            else {
                this.checked = true;
                $(this).parent().css("background-color", "red");
            }
        })
    })
    $(".delete").click(function(){
        var commentIds = new Array();
        switch (currentCommentPanel.attr("id")) {
            case "adminComment":
                currentCommentPanel.find("input:checkbox").each(function(i){
                    if (this.checked == true) {
                        var parentId = $(this).parent().parent().attr("id");
                        parentId = parentId.replace("comment", "")
                        commentIds.push(parentId)
                    }
                })
                getCommonContent("deleteMulitComment", {
                    Ids: commentIds
                }, DeleteMulitCommentCallEvent(), true);
                break;
            case "adminGuestbook":
                currentCommentPanel.find("input:checkbox").each(function(i){
                    if (this.checked == true) {
                        var parentId = $(this).parent().parent().parent().attr("id");
                        parentId = parentId.replace("guestbook", "")
                        commentIds.push(parentId);
                    }
                })
                getCommonContent("deleteMulitGuestbook", {
                    Ids: commentIds
                }, DeleteMulitGuestBookCallEvent(), true);
                break;
            case "adminTrackback":
                currentCommentPanel.find("input:checkbox").each(function(i){
                    if (this.checked == true) {
                        var parentId = $(this).parent().parent().attr("id");
                        parentId = parentId.replace("trackback", "")
                        commentIds.push(parentId);
                    }
                })
                getCommonContent("deleteMulitTrackback", {
                    Ids: commentIds
                }, DeleteMulitTrackbackCallEvent(), true);
                break;
        }
        
    })
}

function DeleteMulitCommentCallEvent(){
    eventbegin = function(){
        $("#ajaxload").html("loading...").show();
    }
    eventend = function(data, param){
        NLBSPage.CommentCall(1);
    }
}

function DeleteMulitGuestBookCallEvent(){
    eventbegin = function(){
        $("#ajaxload").html("loading...").show();
    }
    eventend = function(data, param){
        NLBSPage.GuestBookCall(1);
    }
}

function DeleteMulitTrackbackCallEvent(){
    eventbegin = function(){
        $("#ajaxload").html("loading...").show();
    }
    eventend = function(data, param){
        NLBSPage.TrackBackCall(1);
    }
}

var NLBSPage = {
    ArticleCall: function(currentPage, type, url){
        if (arguments.length == 1) {
            getCommonContent("articleList", {
                page: currentPage
            }, defaultContentEvent());
            return;
        }
        switch (type) {
            case "q":
                getCommonContent("articleList", {
                    q: url,
                    page: currentPage
                }, defaultContentEvent());
                break;
            case "cat":
                getCommonContent("articleList", {
                    catID: url,
                    page: currentPage
                }, defaultContentEvent());
                break;
            case "date":
                
                getCommonContent("articleList", {
                    date: url,
                    page: currentPage
                }, defaultContentEvent());
                break;
            case "selected":
                getCommonContent("articleList", {
                    selected: true,
                    page: currentPage
                }, defaultContentEvent());
            case "user":
                getCommonContent("articleList", {
                    user: url,
                    page: currentPage
                }, defaultContentEvent());
        }
    },
    CommentCall: function(currentPage, type, url){
        if (arguments.length == 1) {
            getCommonContent("commentlist", {
                page: currentPage
            }, CommentCallEvent());
            return;
        }
    },
    TrackBackCall: function(currentPage, type, url){
        if (arguments.length == 1) {
            getCommonContent("trackbacklist", {
                page: currentPage
            }, TrackBackCallEvent());
            return;
        }
    },
    GuestBookCall: function(currentPage, type, url){
        getCommonContent("guestbooklist", {
            page: currentPage
        }, GuestBookCallEvent());
    }
};

function getCheck(obj){
    var objValue = 0;
    $(document.getElementsByName(obj)).each(function(i){
        if (this.checked) 
        
            objValue = this.value;
    });
    return objValue;
}

function closewebsite(){

    getCommonContent('closedSite', {}, closewebsiteEvent(), true);
    
    function closewebsiteEvent(){
        eventend = function(){
            DoCallback('message');
        }
    }
    
}

function openwebsite(){

    getCommonContent('openSite', {}, openwebsiteEvent(), true);
    
    function openwebsiteEvent(){
        eventend = function(){
            DoCallback('message');
        }
    }
}

function clearCache(){
    getCommonContent('clearCache', {}, clearCacheEvent(), true);
    function clearCacheEvent(){
        eventend = function(){
            DoCallback('message');
        }
    }
}


var nlbsEditor = null;
function ReplaceEditToFCKeditor(){
    nlbsEditor = new FCKeditor("editTxt");
    nlbsEditor.ReplaceTextarea();
}

function editWidget(id){
    function widgetEditEvent(){
        eventend = function(data){
            var existEditor = false;
            var showtime = 2000;
            if (nlbsEditor == null) {
                ReplaceEditToFCKeditor();
                existEditor = true;
            }
            $('.ui-dialog-title').html("编辑" + data.Name);
            
            $('#updateWidtetBtn').unbind().bind("click", function(){
                updateWidget();
            })
            
            if (nlbsEditor == null) {
                $("#editTxt").html(data.Content)
                //
            }
            else {
                if (!existEditor) {
                    showtime = 0;
                }
                window.setTimeout(function(){
                    FCKeditorAPI.GetInstance("editTxt").SetHTML(data.Content);
                }, showtime);
            }
            
            $("#editTxt").attr("widgetId", data.WidgetID);
            
            
            $('#editPanel').dialog({
                width: 600,
                height: 300
            }).show();
            $('#editPanel').dialog('open');
        }
    }
    SvcAjax({
        url: "/services/WidgetSvc.ashx/getWidget",
        dataType: "json"
    }, {
        widgetId: id
    }, widgetEditEvent());
}

function updateNLBS(url){
	SvcAjax({
		url: "/services/Utility.ashx/Update"
	}, {
		updateURL: url
	}, updateNLBSEvent());
	function updateNLBSEvent() {
		eventend=function() {
			alert("更新成功,请刷新页面,检测版本号");
		}
	}
}

function updateWidget(){
    var text = null;
    if (nlbsEditor == null) {
        text = $("#editTxt").html();
    }
    else {
        var editor = FCKeditorAPI.GetInstance("editTxt");
        text = editor.GetXHTML(true).toString();
    }
    
    SvcAjax({
        url: "/services/WidgetSvc.ashx/updateWidget"
    }, {
        widgetId: $("#editTxt").attr("widgetId"),
        content: text
    }, widgetEditEvent());
    
    
    function widgetEditEvent(){
        eventend = function(){
            $('#editPanel').dialog('close');
        }
    }
}

